<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript">
require([ "dojo/_base/lang","dojo/_base/array", "dojo/_base/xhr", "dojo/request", "dojo/topic", "dojo/json" ],
  function(lang,array, xhr, request, topic, JSON) {
    conferenceRestForm = function(formId) {
        dojo.byId("_conferenceStarttime").value="";
        dojo.byId("conferenceStarttime").value="";
        dojo.byId("_conferenceEndtime").value="";
        dojo.byId("conferenceEndtime").value="";
        dijit.byId("boardroomSelect").set('options',[{label : '请先选择开始与结束时间' , value : null}]);
        
        dijit.byId("confcontent").setValue("");
        dijit.byId(formId).reset();
    };
    topic.subscribe("conference/insertOrUpdate", conferenceRestForm);
    var syncDB = function(url, jsonData) {
        request.post(url, {
            data : jsonData,
            headers : {
                'Content-Type' : "application/json; charset=utf-8"
            },
            timeout : 30000
        }).then(function(response) {
            topic.publish("notifyMsgTopic", {
                message : response,
                type : "message",
                duration : 1000
            });
        }, function(error) {
            alert(error);
        });
    };
    conferenceSubmitForm = function(formId) {
        var url = "conference/insert";
        var form = dijit.byId(formId);
        if (form.isValid()) {
            ValueCopy();
            var formData=form.getValues();
            lang.mixin(formData, {
                status: "1",
                //审批状态为未审核
                checkstatus: "2"
              });
            var json = JSON.stringify(formData);
            syncDB(url, json);
            topic.publish("conference/insertOrUpdate", formId);
        } else {
            form.validate();
        }
    };
    conferencedraft= function(formId) {
        var url = "conference/insert";
        ValueCopy();
        var formData = dijit.byId(formId).getValues();
        lang.mixin(formData, {
            status: "0",
            //审批状态为未审核
            checkstatus: "2"
          });
        var json = JSON.stringify(formData);
        syncDB(url, json);
        topic.publish("conference/insertOrUpdate", formId);
    };
    
    ValueCopy = function(){
        dojo.byId("_conferenceStarttime").value=dojo.byId("conferenceStarttime").value;
        dojo.byId("_conferenceEndtime").value=dojo.byId("conferenceEndtime").value;
    };
});

require([ "dojo/request", "dojo/ready", "dojo/store/JsonRest", "dojo/json", "dijit/form/CheckBox", "dijit/form/Select" ], function(request, ready, JsonRest, JSON,
        CheckBox, Select) {
    ready(function(){
        new Select({
            name : "roomid",
            style : "width: 80%",
            options : [{label : "请先选择开始与结束时间" , value : null}],
            onChange : function() {
                var romename = dijit.byId("Selectroomname");
                var option = this.getOptions(this.value);
                if(option){
                  romename.setValue(option.label || ""); 
                }
            },
            onMouseEnter : function(event){
                var boardroomSelect = dijit.byId("boardroomSelect");
                if(!(dojo.byId("conferenceStarttime").value=="" || dojo.byId("conferenceEndtime").value=="")){ 
                    request.post("conference/selectBoardRoom?starttime="+dojo.byId("conferenceStarttime").value+"&endtime="+dojo.byId("conferenceEndtime").value+"", {
                        headers : {
                            'Content-Type' : "application/json; charset=utf-8"
                        },
                        timeout : 30000
                    }).then(function(response) {
                        var ops=JSON.parse(response);                        
                        boardroomSelect.set("options",[]);
                        boardroomSelect.reset();
                        boardroomSelect.set("options",ops);
                    }, function(error) {
                        alert(error);
                    });
                }
            } 
        }, "boardroomSelect").startup();
        
        request.post("conference/selectBoardType", {
            headers : {
                'Content-Type' : "application/json; charset=utf-8"
            },
            timeout : 30000
        }).then(function(response) {
            var ops=JSON.parse(response);
            ops.push({label : "&nbsp;&nbsp;", value : "&nbsp;&nbsp;", selected : "true"});
            new Select({
                name : "typeid",
                style : "width: 80%",
                options: ops,
                onChange : function() {
                    var typename = dijit.byId("Selecttypename");
                    var option = this.getOptions(this.value);
                    if(option){
                      typename.setValue(option.label || ""); 
                    }
                }
            }, "boardtypeSelect").startup();
        }, function(error) {
            alert(error);
        });
        
        new CheckBox({
            checked : false,
            onChange : function() {
                var isemail = dijit.byId("email");
                if (this.checked) {
                    isemail.setValue(1);
                } else {
                    isemail.setValue(0);
                }
            }
        }, "emailCheck");
        
        new CheckBox({
            checked : false,
            onChange : function() {
                var ismobile = dijit.byId("mobile");
                if (this.checked) {
                    ismobile.setValue(1);
                } else {
                    ismobile.setValue(0);
                }
            }
        }, "mobileCheck");
    });
});
</script>
<style>
.hander{
    color: #15428B;
    font: bold 12px tahoma,arial,helvetica,sans-serif;
}
.inputwidth{
    width: 80%;
} 
.tdwidthlable{
    width: 10%;
}
.tdwidth{
    width: 40%;
}   
</style>
<div>
<form id="queryconferenceForm" data-dojo-type="dijit/form/Form" action="conference/insert" method="post">
	<table style="width: 100%">
		<tr>
			<td colspan="3">
				<fieldset>
                       <legend>
                           &nbsp;&nbsp;<span class="hander">会议信息</span>&nbsp;&nbsp;
                       </legend>
                       <table style="width: 100%">
                           <tr>
                               <td class="tdwidthlable"><label for="conftopic">会议议题:</label></td>
                               <td class="tdwidth"><input class="inputwidth" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true,required: true" type="text" name="conftopic"></td>
                               <td class="tdwidthlable"><label for="roomname">会议室:</label></td>
                               <td class="tdwidth">
                                   <input id="boardroomSelect">
                                   <input data-dojo-type="dijit/form/TextBox" name="roomname" id="Selectroomname" type="hidden" />
                               </td>
                           </tr>
                           <tr>
                               <td><label for="typeid">会议类型:</label></td>
                               <td>
                                   <input id="boardtypeSelect">
                                   <input data-dojo-type="dijit/form/TextBox" name="typename" id="Selecttypename" type="hidden" />
                               </td>
                               <td><label for="feebudget">费用预算:</label></td>
                               <td><input class="inputwidth" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true,regExp: '^(-?\\d+)(\\.\\d+)?$', invalidMessage:'请输入数字',required: true" type="text" name="feebudget"></td>
                           </tr>
                           <tr>
                               <td><label>留言方式:</label></td>
                               <td>
                                   <label>邮件通知:</label> 
                                   <input id="emailCheck" />
                                   <input data-dojo-type="dijit/form/TextBox" name="isemail" id="email" type="hidden" value="0" >
                                   <label>短信通知:</label> 
                                   <input id="mobileCheck" />
                                   <input data-dojo-type="dijit/form/TextBox" name="ismobile" id="mobile" type="hidden" value="0"/>
                               </td>
                               <td><label>重要级别:</label></td>
                               <td>
                                   <label>普通:</label> 
                                   <input data-dojo-type="dijit/form/RadioButton" name="importlevel" value="1" checked="checked"> 
                                   <label>重要:</label>
                                   <input data-dojo-type="dijit/form/RadioButton" name="importlevel" value="2"> 
                                   <label>非常重要:</label> 
                                   <input data-dojo-type="dijit/form/RadioButton" name="importlevel" value="3">
                               </td>
                           </tr>
                       </table>
                   </fieldset>
			</td>
		</tr>
		<tr>
			<td colspan="3">
				<fieldset>
					<legend>
						&nbsp;&nbsp;<span class="hander">时间和内容设置</span>&nbsp;&nbsp;
					</legend>
                       <table style="width: 100%">
                           <tr>
                               <td class="tdwidthlable"><label for="starttime">开始时间:</label></td>
                               <td class="tdwidth">
                                    <input class="inputwidth" type="text" id="conferenceStarttime" onFocus="WdatePicker({onpicked: function(dp){if(!(dojo.byId('conferenceStarttime').value=='' || dojo.byId('conferenceEndtime').value=='')){dijit.byId('boardroomSelect').set('options',[{label : '请选择会议室' , value : null}]);dijit.byId('boardroomSelect').reset();}}, maxDate:'#F{$dp.$D(\'conferenceEndtime\')}',dateFmt:'yyyy-MM-dd HH:mm:ss'})">
                                    <input class="inputwidth" data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="hidden" name="starttime" id="_conferenceStarttime">
                               </td>
                               <td class="tdwidthlable"><label for="endtime">结束时间:</label></td>
                               <td class="tdwidth">
                                    <input class="inputwidth" type="text" id="conferenceEndtime" onFocus="WdatePicker({onpicked: function(dp){if(!(dojo.byId('conferenceStarttime').value=='' || dojo.byId('conferenceEndtime').value=='')){dijit.byId('boardroomSelect').set('options',[{label : '请选择会议室' , value : null}]);dijit.byId('boardroomSelect').reset();}}, minDate:'#F{$dp.$D(\'conferenceStarttime\')}',dateFmt:'yyyy-MM-dd HH:mm:ss'})">
                                    <input class="inputwidth" data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="hidden" name="endtime" id="_conferenceEndtime">
                               </td>
                           </tr>
                           <tr>
                               <td><label for="confcontent">会议内容: </label></td>
                               <td colspan="3">
                                   <div style="width: 91%" name="confcontent" id='confcontent' data-dojo-type="dijit/Editor" data-dojo-props="plugins:['bold','italic','|','cut','copy','paste','|','insertUnorderedList'], height: 100">
                                   </div>
                               </td>
                           </tr>
                       </table>   
				</fieldset>
			</td>
		</tr>
		<tr>
			<td>
				<fieldset style="height: 100px">
					<legend>
						&nbsp;&nbsp;<span class="hander">参加人员</span>&nbsp;&nbsp;
					</legend>
					<table>
					    <tr>
                               <td style="width: 37%"><label for="compere">主持人:</label></td>
                               <td style="width: 67%">
                                    <input id="comperename" name="comperename" data-dojo-type="dijit/form/TextBox" data-dojo-props="readonly : true" cType="m" onclick="showUserTree(this,'compere');" />
                                    <input id="compere" name="compere" data-dojo-type="dijit/form/TextBox" type="hidden" />
                               </td>
                           </tr>
                           <tr>    
                               <td><label for="recorder">记录人:</label></td>
                               <td>
                                    <input id="recordername" name="recordername" data-dojo-type="dijit/form/TextBox" data-dojo-props="readonly : true" cType="m" onclick="showUserTree(this,'recorder');" />
                                    <input id="recorder" name="recorder" data-dojo-type="dijit/form/TextBox" type="hidden" />
                               </td>
                           </tr>
                           <tr>
                               <td><label for="attendusers">参加人员:</label></td>
                               <td>
                                    <input id="attendusersname" name="attendusersname" data-dojo-type="dijit/form/TextBox" data-dojo-props="readonly : true" cType="m" onclick="showUserTree(this,'attendusers');" />
                                    <input id="attendusers" name="attendusers" data-dojo-type="dijit/form/TextBox" type="hidden" />
                               </td>
                           </tr>
					</table>
				</fieldset>
			</td>
			<td>
				<fieldset style="height: 100px">
					<legend>
						&nbsp;&nbsp;<span class="hander">权限设置</span>&nbsp;&nbsp;
					</legend>
					<table>
                         <tr>
                              <td style="width: 37%"><label for="checkname">审批人: </label></td>
                              <td style="width: 63%">
                                   <input id="checkname" name="checkname" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="readonly : true,required : true" cType="s" onclick="showUserTree(this,'checkuserid');" />
                                   <input id="checkuserid" name="checkuserid" data-dojo-type="dijit/form/TextBox" type="hidden" />
                              </td>
                         </tr>
                       </table>
				</fieldset>
			</td>
		</tr>
		<tr>
			<td colspan="3">
				<fieldset>
					<legend>
						&nbsp;&nbsp;<span class="hander">附件信息</span>&nbsp;&nbsp;							
					</legend>
					<table style="width: 100%">
                              <tr>
                                   <td style="width: 10%"><label for="filename">附件上传:</label></td>
                                   <td style="width: 90%">
                                       <input data-dojo-type="dijit/form/TextBox" name="filename" id="filename" style="width: 80%" onclick="uploadComponet(this,'fileid');"/>
                                       <input data-dojo-type="dijit/form/TextBox" type="hidden" name="fileid" id="fileid" />
                                   </td>
                              </tr>
                       </table>
				</fieldset>
			</td>
		</tr>
		<tr>
		    <td align="center" colspan="2">
		          <button data-dojo-type="dijit/form/Button" type="button" onclick="conferenceSubmitForm('queryconferenceForm')">发送会议通知</button>
		          <button data-dojo-type="dijit/form/Button" type="button" onclick="conferencedraft('queryconferenceForm')">暂存会议</button>
		    </td>
		</tr>
	</table>
</form>
</div>